package nl.sweet.testsweet.gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Toolkit;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JWindow;

import nl.sweet.testsweet.TestSweet;

/**
 * The splash window which pops up on start of the application.
 * @author wessels
 */
public class TestSweetSplash extends JWindow
{
	/** For serialization. */
	private static final long serialVersionUID = 1L;

	/** The image to show as splash screen. */
	private static final String spashImage = "splash.png";

	/**
	 * Contructor.
	 */
	public TestSweetSplash()
	{
		super();
		setAlwaysOnTop(true);
		setBackground(Color.WHITE);
		getContentPane().setBackground(Color.WHITE);

		// Create a panel with a white brackground and a border.
		JPanel splashPanel = new JPanel(new BorderLayout());
		splashPanel.setOpaque(false);
		splashPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK));

		// Create the splash image and version label and add it to the panel.
		JLabel image = new JLabel(new ImageIcon(TestSweetSplash.class.getResource(spashImage)));
		splashPanel.add(image, BorderLayout.CENTER);
		JPanel bottomPanel = new JPanel(new BorderLayout());
		bottomPanel.setOpaque(false);
		bottomPanel.add(new JLabel(" Loading..."), BorderLayout.WEST);
		bottomPanel.add(new JLabel("Version " + TestSweet.APPLICATON_VERSION + " "),
				BorderLayout.EAST);
		splashPanel.add(bottomPanel, BorderLayout.SOUTH);

		// Add the panel to the window.
		getContentPane().add(splashPanel);

		// Pack the window and align in the center of the screen.
		pack();
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		Dimension labelSize = getSize();
		setLocation(screenSize.width / 2 - (labelSize.width / 2), screenSize.height
				/ 2 - (labelSize.height / 2));

		// Show the splash screen.
		setVisible(true);
	}
}
